package com.example.houseitemmanagebackend.controller;

import com.example.houseitemmanagebackend.entity.UserSetting;
import com.example.houseitemmanagebackend.security.JwtUserDetails;
import com.example.houseitemmanagebackend.service.SettingService;
import com.example.houseitemmanagebackend.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

/**
 * 系统设置控制器
 */
@Tag(name = "系统设置", description = "系统设置相关接口")
@RestController
@RequestMapping("/settings")
public class SettingController {

    @Autowired
    private SettingService settingService;

    @Operation(summary = "获取用户设置", description = "获取用户设置接口")
    @GetMapping
    public Result<UserSetting> getUserSetting(@AuthenticationPrincipal JwtUserDetails userDetails) {
        return Result.success(settingService.getUserSetting(userDetails.getId()));
    }

    @Operation(summary = "更新用户设置", description = "更新用户设置接口")
    @PutMapping
    public Result<Void> updateUserSetting(@RequestBody UserSetting setting,
            @AuthenticationPrincipal JwtUserDetails userDetails) {
        settingService.updateUserSetting(setting, userDetails.getId());
        return Result.success();
    }
}